package org.microframework.base.core.datasource;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 数据库配置属性类
 */
@Component
@ConfigurationProperties(prefix = "micro.datasource")
public class DatabaseProperties {
    
    /**
     * 是否启用数据源模块，默认为true
     */
    private boolean enabled = true;
    
    /**
     * 数据源类型
     */
    private String type;
    
    /**
     * 数据库驱动类名
     */
    private String driverClassName;
    
    /**
     * 数据库连接URL
     */
    private String url;
    
    /**
     * 数据库用户名
     */
    private String username;
    
    /**
     * 数据库密码
     */
    private String password;

    /**
     * ActiveRecord配置
     */
    private final ActiveRecord activeRecord = new ActiveRecord();
    
    // Getter and Setter
    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }
    
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDriverClassName() {
        return driverClassName;
    }

    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    public ActiveRecord getActiveRecord() {
        return activeRecord;
    }
    
    /**
     * ActiveRecord 配置
     */
    public static class ActiveRecord {
        /**
         * 是否启用 ActiveRecord，默认为true
         */
        private boolean enabled = true;
        
        /**
         * 是否显示SQL，默认为false
         */
        private boolean showSql = false;
        
        /**
         * 数据源名称
         */
        private String datasourceName = "main";
        
        /**
         * 是否开发模式
         */
        private boolean devMode = true;
        
        /**
         * 事务级别
         * 0: TRANSACTION_NONE
         * 1: TRANSACTION_READ_UNCOMMITTED
         * 2: TRANSACTION_READ_COMMITTED
         * 4: TRANSACTION_REPEATABLE_READ
         * 8: TRANSACTION_SERIALIZABLE
         */
        private int transactionLevel = 2; // 默认 TRANSACTION_READ_COMMITTED
        
        /**
         * 是否不区分大小写
         */
        private boolean caseInsensitive = false;
        
        /**
         * 批处理大小
         */
        private int batchSize = 0;
        
        /**
         * 查询超时时间（秒）
         */
        private int queryTimeOut = 0;
        
        /**
         * 是否启用缓存
         */
        private boolean enableCache = false;
        
        /**
         * 映射类
         */
        private String[] mappingClasses;
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public boolean isShowSql() {
            return showSql;
        }
        
        public void setShowSql(boolean showSql) {
            this.showSql = showSql;
        }
        
        public String getDatasourceName() {
            return datasourceName;
        }
        
        public void setDatasourceName(String datasourceName) {
            this.datasourceName = datasourceName;
        }
        
        public boolean isDevMode() {
            return devMode;
        }
        
        public void setDevMode(boolean devMode) {
            this.devMode = devMode;
        }
        
        public int getTransactionLevel() {
            return transactionLevel;
        }
        
        public void setTransactionLevel(int transactionLevel) {
            this.transactionLevel = transactionLevel;
        }
        
        public boolean isCaseInsensitive() {
            return caseInsensitive;
        }
        
        public void setCaseInsensitive(boolean caseInsensitive) {
            this.caseInsensitive = caseInsensitive;
        }
        
        public int getBatchSize() {
            return batchSize;
        }
        
        public void setBatchSize(int batchSize) {
            this.batchSize = batchSize;
        }
        
        public int getQueryTimeOut() {
            return queryTimeOut;
        }
        
        public void setQueryTimeOut(int queryTimeOut) {
            this.queryTimeOut = queryTimeOut;
        }
        
        public boolean isEnableCache() {
            return enableCache;
        }
        
        public void setEnableCache(boolean enableCache) {
            this.enableCache = enableCache;
        }
        
        public String[] getMappingClasses() {
            return mappingClasses;
        }
        
        public void setMappingClasses(String[] mappingClasses) {
            this.mappingClasses = mappingClasses;
        }
    }
} 